public class Prefix2 {
    public int[] productExceptSelf(int[] nums) {
        int len = nums.length;
        int[] dp1 = new int[len + 1];//前缀积
        int[] dp2 = new int[len + 1];//后缀积
        dp1[0] = 1;
        dp2[0] = 1;
        for (int i = 1; i < len + 1; i++) {
            dp1[i] = dp1[i - 1] * nums[i - 1];
            dp2[i] = dp2[i - 1] * nums[len - i];
        }
        int[] answer = new int[len];
        for (int i = 0; i < len; i++) {
            answer[i] = dp1[i] * dp2[len - 1 - i];
        }
        return answer;
    }
}
